<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta name="description" content="">
	<meta name="author" content="">
	<link rel="shortcut icon" href="images/favicon.png">

	<title>mzcms后台登录</title>
	<link rel="stylesheet" type="text/css" href="/cleanzone/js/bootstrap/dist/css/bootstrap.css">
	<link rel="stylesheet" type="text/css" href="/css/awesome/css/font-awesome.min.css">
	<link rel="stylesheet" type="text/css" href="/cleanzone/css/style.css"/>
</head>

<body class="texture">

<div id="cl-wrapper" class="login-container">

	<div class="middle-login">
		<div class="block-flat">
			<div class="header">							
				<h3 class="text-center">MzCms后台管理系统</h3>
			</div>
			<div>
				<form style="margin-bottom: 0px !important;" class="form-horizontal" onsubmit="return false" id="login-form">
                    <input type="hidden" name="<?=Yii::$app->request->csrfParam?>" value="<?=Yii::$app->request->csrfToken?>">
					<div class="content">
                        <h5 class="title text-center"><b>温馨提示：</b><span id="message">请输入您的账号密码</span></h5>
                        <div class="form-group">
                            <div class="col-sm-12">
                                <div class="input-group">
                                    <span class="input-group-addon"><i class="fa fa-user"></i></span>
                                    <input type="text" placeholder="用户名" name="username" value="" class="form-control">
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-12">
                                <div class="input-group">
                                    <span class="input-group-addon"><i class="fa fa-lock"></i></span>
                                    <input type="password" placeholder="密码" name="password_hash" class="form-control">
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-12">
                                <div class="input-group">
                                    <span class="input-group-addon"><i class="fa fa-arrow-circle-o-right"></i></span>
                                    <input type="text" placeholder="验证码" name="captcha" class="form-control">
                                    <span class="input-group-addon" style="padding: 0px;margin: 0px">
                                        <img id="captcha" src="<?=\yii\helpers\Url::toRoute('admin/login/captcha')?>"/>
                                    </span>
                                </div>
                            </div>
                        </div>
					</div>
					<div class="foot">
<!--						<button class="btn btn-default" data-dismiss="modal" type="button">Register</button>-->
                        <button class="btn btn-primary" onclick="loginObj.doLogin()"><i class="fa fa-sign-in"></i> 登 录</button>
					</div>
				</form>
			</div>
		</div>
		<div class="text-center out-links"><a href="#">&copy; <?=date('Y')?>版权所有 fankers</a></div>
	</div> 
</div>

<script type="text/javascript" src="/cleanzone/js/jquery.js"></script>
<script type="text/javascript" src="/cleanzone/js/behaviour/general.js"></script>
<script type="text/javascript" src="/cleanzone/js/behaviour/voice-commands.js"></script>
<script type="text/javascript" src="/cleanzone/js/bootstrap/dist/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/cleanzone/js/jquery.flot/jquery.flot.js"></script>
<script type="text/javascript" src="/cleanzone/js/jquery.flot/jquery.flot.pie.js"></script>
<script type="text/javascript" src="/cleanzone/js/jquery.flot/jquery.flot.resize.js"></script>
<script type="text/javascript" src="/cleanzone/js/jquery.flot/jquery.flot.labels.js"></script>


<script type="text/javascript">
    var captcha = $('#captcha');
    captcha.css('cursor','pointer');

    var loginObj = {
        loginLock : false,

        // 刷新验证码
        refreshCaptcha:function () {
            var src = "<?=\yii\helpers\Url::toRoute('admin/login/captcha')?>";
            $('#captcha').attr('src',src+'?v='+Math.random()*100000000000000000);
        },

        // 登录
        doLogin:function () {
            var data = $('#login-form').serialize();
            var url = '<?=\yii\helpers\Url::toRoute('admin/login/oauth')?>';
            that = this;

            if (that.loginLock)return false;
            that.loginLock = true;

            $.ajax({
                type:'post',
                url:url,
                data:data,
                dataType:'json',
                success:function(data){
                    that.loginLock = false;
                    $("#message").html(data.message);
                    window.location.href = '<?=\yii\helpers\Url::to(['admin/'])?>';
                    that.refreshCaptcha();
                },
                error:function(err){
                    that.loginLock = false;
                    console.log(err);
                    throw err;
                }
            });
        }
    };

    // 执行刷新验证码
    captcha.click(loginObj.refreshCaptcha());

</script>

</body>

</html>
